package com.elvende.web.server;

import java.util.List;

import javax.jdo.Query;

import com.elvende.web.client.dto.Category;
import com.elvende.web.client.service.CategoryService;

public class CategoryServiceImpl extends BaseServiceImpl implements CategoryService{

	private static final long serialVersionUID = 1L;	
		
	public Category addCategory(Category e) {	
	        pm.makePersistent(e);	    
	        return e;   		
	}

	public Category editCategory(Category e) {		
		return null;
	}
	
	public Boolean deleteCategory(Category e) {
			Category c = (Category) pm.getObjectById(Category.class,e.getKey());
			if (c != null){
				pm.deletePersistent(c);
				return true;
			}
	        return false;	     
	}
	
	public Category[] listCategory() {
		Query query = pm.newQuery(Category.class);
//	    query.setFilter("name == nameParam");
//	    query.declareParameters("String nameParam");
	    
	    Category[] list = null;
		 try {			 	
		        List<Category> results = (List<Category>) query.execute();
		        list = new Category[results.size()];
		        for (int i=0; i<results.size(); i++){
		        	list[i] = (Category) results.get(i);	
		        }
		        // list = (AffortableHousing[])results.toArray(new AffortableHousing[]{});
		        
		    } finally {
		        query.closeAll();
		 }		
		return list;		
	}
	
	public String getModuleName() { return "category"; }
}
